package com.example.shop_2210

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.lifecycleScope
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.example.base.mvvm.BaseViewActivity
import com.example.shop_2210.databinding.ActivityMainBinding
import com.example.shop_2210.login.LoginCodeActivity
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

/**
 * 欢迎页
 */
class MainActivity : BaseViewActivity<ActivityMainBinding>() {
    override fun initData() {
    }

    override fun initView() {
        //binding.time = 3
        binding.imgurl = "http://10.161.9.80:8080/crmebimage/public/maintain/2021/12/25/a272fcefed804cf2b1e6785d5662c29ejqjxha0eow.jpg"
        //下次打开不在展示
      /*  if(SPUtils.getInstance().getBoolean("isFrist")){
            //startActivity(Intent(this@MainActivity,LoginCodeActivity::class.java))
            ARouter.getInstance().build("/app/LoginCodeActivity").navigation()//实现跳转到指定界面
            finish()
        }*/
        //使用协程方式实现倒计时
        lifecycleScope.launch {
            for(i in 5 downTo 1){
                binding.time  =i
                delay(1000)
                if(i==1){
                    //startActivity(Intent(this@MainActivity,LoginCodeActivity::class.java))
                    ARouter.getInstance().build("/app/ShopActivity").navigation()//实现跳转到指定界面
                   /* if(SPUtils.getInstance().getString("token").isNotEmpty()){
                        ARouter.getInstance().build("/app/ShopActivity").navigation()//实现跳转到指定界面
                    }else{
                        ARouter.getInstance().build("/app/LoginCodeActivity").navigation()//实现跳转到指定界面
                    }*/

                    finish()
                    //保存展示状态
                    SPUtils.getInstance().put("isFrist",true)
                }
            }
        }
        //点击跳过，不重复闪屏
        binding.tg.setOnClickListener {
            finish()
            //startActivity(Intent(this@MainActivity,LoginCodeActivity::class.java))
            ARouter.getInstance().build("/app/LoginCodeActivity").navigation()//实现跳转到指定界面
            SPUtils.getInstance().put("isFrist",true)
        }

    }

    override fun getLayout(): Int  = R.layout.activity_main

}